package com.liu.communitysystemend.module.notice.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.liu.communitysystemend.module.notice.domain.Notice;
import com.liu.communitysystemend.module.notice.service.NoticeService;
import com.liu.communitysystemend.utils.Result;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author liu
 * @create 2023-03-01 17:31
 */
@RestController
@RequestMapping("/api/notice")
public class NoticeController {
    @Autowired
    private NoticeService noticeService;

    @ApiOperation("添加通告信息")
    @GetMapping("/get/{id}")
    public Result<Notice> getMenu(@PathVariable("id")String id){
        return Result.success(noticeService.getNoticeById(id));
    }

    @ApiOperation("更新通告信息")
    @PostMapping("modify")
    public Result<Notice> save(@RequestBody Notice notice) {
        return Result.success(noticeService.update(notice));
    }

    @ApiOperation("添加通告信息")
    @PostMapping("add")
    public Result<Notice> add(@RequestBody Notice notice){
        return Result.success(noticeService.add(notice));
    }

    @ApiOperation("查询通告列表(分页)")
    @PostMapping("page")
    public Result<Page<Notice>> getPage(@RequestBody Notice notice) {
        return Result.success(noticeService.getPage(notice));
    }

    @GetMapping("delete/{id}")
    @ApiOperation("删除通告")
    public Result deleteById(@PathVariable("id") String id) {
        return noticeService.deleteById(id) > 0 ? Result.success() : Result.failed();
    }
}
